#include <stdio.h>
#include <iostream>
#define OK 1
#define MAX_VERTEX_NUM 20
using namespace std;
typedef enum {DG, DN, UDG, UDN} GraphKind;
typedef int VertexInfo; // 每个数字代表一个节点
typedef struct ArcNode
{
    int adjvex;    // 节点数组中某点的索引
    int *info;     // 可以作为网中边的权
    ArcNode *next; // 指向下一个邻接边
} ArcNode;
typedef struct VNode
{
    VertexInfo data;
    ArcNode *firstArc;
} VNode, AdjList[MAX_VERTEX_NUM]; 
typedef struct
{
    AdjList vertices; // AdjList中应存MAX_VERTEX_NUM个指针
    int vexnum, arcnum;
    GraphKind kind;
} ALGraph;
typedef int Status;
Status createDG(ALGraph& G) {
    G.kind = DG;
    G.vexnum = 4;
    G.arcnum = 4;
    for (int i = 0; i < G.vexnum; ++i) {
        G.vertices[i].data = i;
    }
    // 节点1
    ArcNode* cur1 = new ArcNode;
    cur1->adjvex = 1;
    ArcNode* cur2 = new ArcNode;
    G.vertices[0].firstArc = cur1;
    cur2->adjvex = 2;
    cur1->next = cur2;
    cur2->next = nullptr;

    // 节点2
    G.vertices[1].firstArc = nullptr;

    // 节点3
    ArcNode* cur3 = new ArcNode;
    cur3->adjvex = 3;
    cur3->next = nullptr;
    G.vertices[2].firstArc = cur3;

    // 节点4
    ArcNode* cur4 = new ArcNode;
    cur4->adjvex = 0;
    cur4->next = nullptr;
    G.vertices[3].firstArc = cur4;

    return OK;
}
void showDG(ALGraph G) {
    int n = G.vexnum;
    for (int i = 0; i < n; ++i) {
        cout << G.vertices[i].data + 1; // 输出当前节点
        ArcNode* cur = G.vertices[i].firstArc;
        while (cur) {
            cout << " -> " << cur->adjvex + 1;
            cur = cur->next;
        }
        cout << endl;
    }
}
int main(void)
{
    ALGraph G;
    createDG(G);
    showDG(G);

    return 0;
}